package pikes.uri;

import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

public class RelativeURITestCase {

	@Test
	public void createAndPrint() throws Exception {
		RelativeURI uri = new RelativeURI("path");
		StringWriter writer = new StringWriter();
		uri.print(writer);
		Assert.assertEquals("/path", writer.toString());

	}

	@Test
	public void createAndPrint2() throws Exception {
		RelativeURI uri = new RelativeURI("/path");
		StringWriter writer = new StringWriter();
		uri.print(writer);
		Assert.assertEquals("/path", writer.toString());

	}

	@Test
	public void equals() throws Exception {
		Assert.assertEquals(new RelativeURI("path"), new RelativeURI("path"));

	}

	@Test
	public void equals2() throws Exception {
		Assert.assertEquals(new RelativeURI("path"), new RelativeURI("/path"));

	}

	@Test
	public void equals1() throws Exception {
		Map<CharSequence, CharSequence> parameters = new LinkedHashMap<CharSequence, CharSequence>();
		parameters.put("group_id", "73357");
		Map<CharSequence, CharSequence> parameters1 = new LinkedHashMap<CharSequence, CharSequence>();
		parameters1.put("id", "73357");

		Assert.assertTrue(!new RelativeURI("path", parameters).equals(new RelativeURI("path", parameters1)));

	}

	@Test
	public void createAndPrint1() throws Exception {
		RelativeURI uri = new RelativeURI(new URI() {

			public void print(Appendable appendable) throws IOException {
				appendable.append("parent");

			}

		}, "path");
		StringWriter writer = new StringWriter();
		uri.print(writer);
		Assert.assertEquals("parent/path", writer.toString());

	}

	@Test
	public void createWithQueryParameterAndPrint() throws Exception {
		Map<CharSequence, CharSequence> parameters = new LinkedHashMap<CharSequence, CharSequence>();
		parameters.put("group_id", "73357");
		RelativeURI uri = new RelativeURI("path", parameters);
		StringWriter writer = new StringWriter();
		uri.print(writer);
		Assert.assertEquals("/path?group_id=73357", writer.toString());

	}

	@Test
	public void createWithQueryParameterAndPrint1() throws Exception {
		Map<CharSequence, CharSequence> parameters = new LinkedHashMap<CharSequence, CharSequence>();
		parameters.put("group_id", "73357");
		parameters.put("emp_id", "800544");
		RelativeURI uri = new RelativeURI("path", parameters);
		StringWriter writer = new StringWriter();
		uri.print(writer);
		Assert.assertEquals("/path?group_id=73357&emp_id=800544", writer.toString());

	}
}
